package com.example.auth.config.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;

import java.io.IOException;

public class OidcUserSerializer extends StdSerializer<OidcUser> {

    public OidcUserSerializer() {
        super(OidcUser.class);
    }

    @Override
    public void serialize(OidcUser value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();
        gen.writeStringField("sub", value.getSubject());
        gen.writeStringField("email", value.getEmail());
        gen.writeStringField("name", value.getFullName());
        gen.writeStringField("picture", value.getPicture());
        gen.writeObjectField("claims", value.getClaims());
        gen.writeEndObject();
    }
} 